package com.jlnk.stockdemo.bean;

import com.google.gson.annotations.SerializedName;

import java.util.ArrayList;
import java.util.List;

public class NewsResponse {

    @SerializedName("request_id")
    private String requestId;

    @SerializedName("code")
    private int code;

    @SerializedName("data")
    private Data data;

    @SerializedName("msg")
    private String msg;

    public String getRequestId() {
        return requestId;
    }

    public int getCode() {
        return code;
    }

    public Data getData() {
        return data;
    }

    public String getMsg() {
        return msg;
    }

    public static class Data {
        @SerializedName("fields")
        private List<String> fields;

        @SerializedName("items")
        private List<List<String>> items;

        @SerializedName("has_more")
        private boolean hasMore;

        @SerializedName("count")
        private int count;

        private List<News> newsList;

        // Getters and Setters
        public List<String> getFields() {
            return fields;
        }

        public List<List<String>> getItems() {
            return items;
        }

        public boolean isHasMore() {
            return hasMore;
        }

        public int getCount() {
            return count;
        }

        public List<News> getNewsList() {
            newsList = new ArrayList<>();
            int titleIndex, datetimeIndex, contentIndex;
            titleIndex = datetimeIndex = contentIndex = 0;
            for (int i = 0; i < fields.size(); i++) {
                switch (fields.get(i)) {
                    case "title" :
                        titleIndex = i;
                        break;
                    case "datetime" :
                        datetimeIndex = i;
                        break;
                    case "content" :
                        contentIndex = i;
                        break;
                }
            }
            for (int j = 0; j < items.size(); j++) {
                News news = new News();
                news.setTitle(items.get(j).get(titleIndex));
                news.setDateTime(items.get(j).get(datetimeIndex));
                news.setContent(items.get(j).get(contentIndex));
                newsList.add(news);
            }
            return newsList;
        }

        public static class News {
            private String title;
            private String dateTime;
            private String content;

            public String getTitle() {
                return title;
            }

            public void setTitle(String title) {
                this.title = title;
            }

            public String getDateTime() {
                return dateTime;
            }

            public void setDateTime(String dateTime) {
                this.dateTime = dateTime;
            }

            public String getContent() {
                return content;
            }

            public void setContent(String content) {
                this.content = content;
            }
        }
    }
}
